using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TerritoryGame.Application.Services;
using TerritoryGame.Application.Interfaces;
using TerritoryGame.Domain.Interfaces;
using TerritoryGame.Domain.DomainEvents;

namespace TerritoryGame.Application;

public static class ServicesCollectionExtensition
{
    public static IServiceCollection AddApplicationServices(this IServiceCollection services)
    {
        // 用户相关服务
        services.AddScoped<IAppUserService, AppUserService>();
        services.AddScoped<IAppAuthService, AppAuthService>();
        services.AddScoped<IAppAvatarService, AppAvatarService>();
        services.AddScoped<IAppTokenService, AppTokenService>();
        
        // 游戏相关服务
        services.AddScoped<IAppGameService, AppGameService>();
        services.AddScoped<IAppGameHistoryService, AppGameHistoryService>();
        services.AddScoped<IAppGameStatsService, AppGameStatsService>();
        
        // 用户等级服务
        services.AddScoped<IAppUserLevelService, AppUserLevelService>();
        
        // 系统服务
        services.AddScoped<IAppSystemService, AppSystemService>();
        services.AddScoped<IAppLogService, AppLogService>();
        
        // 游戏缓存服务
        services.AddScoped<IGameCacheService, GameCacheService>();
        
        // 领域事件发布器
        services.AddScoped<IDomainEventPublisher, DomainEventPublisher>();
        
        // 事件处理器（按接口注册，供发布器按泛型解析）
        services.AddScoped<IDomainEventHandler<UserCreatedEvent>, UserCreatedEventHandler>();
        services.AddScoped<IDomainEventHandler<UserLoggedInEvent>, UserLoggedInEventHandler>();
        services.AddScoped<IDomainEventHandler<UserLoginFailedEvent>, UserLoginFailedEventHandler>();
        services.AddScoped<IDomainEventHandler<UserRegisteredEvent>, UserRegisteredEventHandler>();

        return services;
    }
}